<template>
  <div>
    <van-nav-bar
      :title="
        comment.reply_count ? comment.reply_count + '条 回复' : '暂无回复'
      "
      left-text="返回"
      @click-left="$emit('close')"
    >
      <template #left> <van-icon name="cross" size="18"></van-icon> </template
    ></van-nav-bar>

    <div class="scroll-box">
      <comment-item :comment="comment"> </comment-item>
      <van-cell title="全部回复"></van-cell>
      <comment-list
        type="c"
        :source="comment.com_id + ''"
        :list="list"
      ></comment-list>
    </div>

    <div class="post-warp">
      <van-button round @click="isShowReplyComment = true">评论</van-button>
    </div>

    <van-popup v-model="isShowReplyComment" round position="bottom">
      <comment-post
        :target="comment.com_id + ''"
        :artId="$route.params.artId"
        @on-success="onSuccess"
      ></comment-post>
    </van-popup>
  </div>
</template>

<script>
import CommentItem from '@/components/CommentItem'
import CommentList from './CommentList'
import CommentPost from './CommentPost'
export default {
  components: { CommentItem, CommentList, CommentPost },
  data () {
    return {
      list: [],
      isShowReplyComment: false
    }
  },
  props: {
    comment: {
      type: Object,
      required: true
    }
  },

  created () {},

  methods: {
    onSuccess (e) {
      this.list.unshift(e)
      this.isShowReplyComment = false
      this.comment.reply_count++
    }
  }
}
</script>

<style scoped lang="less">
.post-warp {
  width: 100%;
  height: 100px;
  position: fixed;
  bottom: 0;
  border-top: 1px solid #ccc;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: rgb(117, 200, 248);
  .van-button {
    width: 640px;
    height: 80px;
  }
}
.scroll-box {
  position: absolute;
  width: 100%;
  top: 92px;
  bottom: 100px;
  overflow-y: scroll;
}
</style>
